//package cn.lhemi.iotweb.configure;
//
//import cn.lhemi.iotweb.util.R;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.http.HttpStatus;
//import org.springframework.security.core.AuthenticationException;
//import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.io.PrintWriter;
//
///**
// * @author tutu11
// * @description 验证端口
// * @date 2020-03-12 18:08:31
// */
////@Component
//public class AuthenticationPoint extends BasicAuthenticationEntryPoint {
//    private final static ObjectMapper MAPPER = new ObjectMapper();
//
//    @Override
//    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authEx)throws IOException {
////        response.addHeader("WWW-Authenticate", "Basic realm=" + getRealmName());
//        response.setStatus(HttpStatus.UNAUTHORIZED.value());
//        response.setCharacterEncoding("utf-8");
//        response.setHeader("Content-Type", "application/json;charset=UTF-8");
//        PrintWriter writer = response.getWriter();
//        writer.println(MAPPER.writeValueAsString(R.failed(authEx.getMessage())));
//    }
//
//    @Override
//    public void afterPropertiesSet() {
//        setRealmName("client");
//        super.afterPropertiesSet();
//    }
//}
